/*
 * 1314. Power of Two
 * Given an integer, write a function to determine if it is a power of two.
 * 
 * 2018.06.12 @jeyming
 */
package power_of_two_1314;

public class Power_of_two_1314 {
	 /**
     * @param n: an integer
     * @return: if n is a power of two
     */
    public static boolean isPowerOfTwo(int n) {
        // Write your code here
    	boolean judge = false;
    	while(n > 0) {
    		if(n == 1) {
    			judge = true;
    			break;
    		}
    		if((n % 2 != 0) && (n != 1)) {
    			break;
    		}
    		if((n % 2 == 0) && (n/2 == 1)) {
    			judge = true;
    		}
    		n /= 2;
    	}
        return judge;
    }

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(isPowerOfTwo(0));
		System.out.println(isPowerOfTwo(1));
		System.out.println(isPowerOfTwo(2));
		System.out.println(isPowerOfTwo(3));
		System.out.println(isPowerOfTwo(8));

	}

}
